package com.cvs.service.impl;

import com.cvs.bean.Sign;
import com.cvs.dao.SignMapper;
import com.cvs.service.SignService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service("signService")
public class SignServiceImpl implements SignService {
    @Autowired
    private SignMapper signMapper;
    @Override
    public int addSign(Sign sign) {
        if(signMapper.getSign(sign.getUid())>0){
            return -1;//代表当天已经签到过
        }else{
            return signMapper.addSign(sign);
        }
    }

    @Override
    public List<Sign> signDay(Integer uid) {
        return signMapper.signDay(uid);
    }

    @Override
    public int signCount(Integer uid) {
        List<Sign> signs =signMapper.signDay(uid);
        int sday=0;
        int count=0;
        for (Sign sign:signs) {//连续不连续
            //1.当前统计1月内容累计签到次数
            //2.当天日期数
            //判断小于等于当天签到
            if (sday==0){//初始化开始日期
                sday=sign.getDay();
                count=1;
            }else{//不是初始值
                if(sday+1==sign.getDay()){
                    sday=sign.getDay();
                    count=count+1;
                }else{
                    sday=sign.getDay();
                    count=1;
                }
            }
        }
        return count;
    }
}
